using System.Collections.Generic;
using UnityEngine;

public class QuestScrollFactory : MonoBehaviour
{
	public GameObject ScrollPanel;

	public GameObject NoJobs;

	public butQuestInfo ContainerButtonMission;

	public GameObject LabelJobs;

	private int sizeSmallCompletedBG = 150;

	private int sizeLargeCompletedBG = 214;

	private List<butQuestInfo> _questContainer = new List<butQuestInfo>();

	private void Start()
	{
		ContainerButtonMission.gameObject.SetActive(false);
	}

	private void OnEnable()
	{
		NoJobs.SetActive(false);
		foreach (butQuestInfo item in _questContainer)
		{
			Object.Destroy(item.gameObject);
		}
		_questContainer.Clear();
		if (ManagerMissions.instance == null)
		{
			BCWDebug.LogError("ManagerMission.instance==null");
			return;
		}
		List<TargetParameter> startedTargetsAllMission = ManagerMissions.instance.GetStartedTargetsAllMission();
		int count = startedTargetsAllMission.Count;
		if (count == 0)
		{
			LabelJobs.SetActive(false);
			NoJobs.SetActive(true);
		}
		else
		{
			LabelJobs.SetActive(true);
		}
		for (int i = 0; i < count; i++)
		{
			TargetParameter targetParameter = startedTargetsAllMission[i];
			butQuestInfo butQuestInfo2 = Object.Instantiate(ContainerButtonMission);
			butQuestInfo2.transform.parent = ScrollPanel.transform;
			butQuestInfo2.transform.localScale = Vector3.one;
			butQuestInfo2.gameObject.SetActive(true);
			butQuestInfo2.transform.localPosition = ContainerButtonMission.transform.localPosition + new Vector3(0f, -ContainerButtonMission.ContainerGrid.height * i, 0f);
			butQuestInfo2.QuestText.text = targetParameter.curMission.title;
			if (targetParameter.isComplete)
			{
				butQuestInfo2.QuestCompletedBG.gameObject.SetActive(true);
				butQuestInfo2.CompletedText.SetActive(true);
				butQuestInfo2.QuestCompletedBG.width = sizeLargeCompletedBG;
			}
			else
			{
				butQuestInfo2.QuestCompletedBG.gameObject.SetActive(false);
				butQuestInfo2.CompletedText.SetActive(false);
				butQuestInfo2.QuestCompletedBG.width = sizeSmallCompletedBG;
			}
			_questContainer.Add(butQuestInfo2);
		}
	}
}
